# Maintainer: Peter Budai <peterbudai at hotmail dot com>

_realname=libgphoto2
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.5.23
pkgrel=2
pkgdesc="libgphoto2 is a free, redistributable, ready to use set of digital camera software applications for Unix-like system (mingw-w64)"
arch=('any')
url="http://gphoto.org/proj/libgphoto2/"
license=("LGPL")
depends=("${MINGW_PACKAGE_PREFIX}-libsystre"
         "${MINGW_PACKAGE_PREFIX}-libjpeg"
         "${MINGW_PACKAGE_PREFIX}-libxml2"
         "${MINGW_PACKAGE_PREFIX}-libgd"
         "${MINGW_PACKAGE_PREFIX}-libexif"
         "${MINGW_PACKAGE_PREFIX}-libusb"
         "${MINGW_PACKAGE_PREFIX}-libtool")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-doxygen")
source=(https://sourceforge.net/projects/gphoto/files/libgphoto/${pkgver}/${_realname}-${pkgver}.tar.gz
        libgphoto2-gp_system_filename-fix.patch
        libgphoto2-use-pkg-config-for-gd.patch)
sha256sums=('58bdb621f58e95775103bca8d530c3e63d11e42bfde3d2447bf5e9fad8144da2'
            '27c558cdf88bee6ce1f3f564d6dfbc0b78809c33b98d20c9e58e40e335d7b0dd'
            '16036711f9c656e3988bc3c7b3e5209db3ad1163048cc7a0139e3e882d52f7c2')
validpgpkeys=('7C4AFD61D8AAE7570796A5172209D6902F969C95') # Marcus Meissner 

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -Np1 -i "${srcdir}/libgphoto2-gp_system_filename-fix.patch"
  patch -Np1 -i "${srcdir}/libgphoto2-use-pkg-config-for-gd.patch"
  autoreconf -fiv
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  #mkdir -p ${srcdir}/build-${MINGW_CHOST} && cd ${srcdir}/build-${MINGW_CHOST}
  #Note: --with-libusb=no is required for Windows 10 to work.
  cp -rf ${_realname}-${pkgver} build-${MINGW_CHOST}
  cd ${srcdir}/build-${MINGW_CHOST}
  
  ./configure \
    --prefix="${MINGW_PREFIX}"      \
    --build=${MINGW_CHOST}          \
    --host=${MINGW_CHOST}           \
    --with-libusb=no \
    --with-gdlib=auto \
    --enable-internal-docs

  make
}

check() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make check
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR=${pkgdir} install

  # Remove unused udev helper
  rm -rf "${pkgdir}/${MINGW_PREFIX}/lib/udev"

  # Remove recursive symlink
  rm -rfv "${pkgdir}/${MINGW_PREFIX}/include/gphoto2/gphoto2"  

  # install profile script
  mkdir -p "${pkgdir}${MINGW_PREFIX}"/etc/profile.d

  cat > ${pkgdir}${MINGW_PREFIX}/etc/profile.d/${_realname}.sh <<EOF
export CAMLIBS=${MINGW_PREFIX}/lib/${_realname}/${pkgver}
export IOLIBS=${MINGW_PREFIX}/lib/${_realname}_port/0.12.0
EOF

}
